const express = require("express")

const router = express.Router()

var mysql = require('mysql');
var pool = mysql.createPool({
    connectionLimit: 10,
    host: 'localhost',//服务器地址
    user: 'root',//用户名
    password: 'root',//密码
    database: 'demo'//数据库名字
});

// 
router.post("/login", (req, res) => {
    pool.getConnection(function (err, connection) {
        if (err) throw err; // not connected!

        // Use the connection
        connection.query('SELECT * FROM user where username = ? and password = ? limit 1',[req.body.username,req.body.password] ,function (error, results, fields) {
            // When done with the connection, release it.
            connection.release();
                console.log("results",results)
            // Handle error after the release.
            if (error) throw error;

            // Don't use the connection here, it has been returned to the pool.
        });
    });
})

module.exports = router